<script>
	var JYGoogleAdMob = uni.requireNativePlugin("JY-GoogleAdMob"); 
	import {
		mapActions,
		mapGetters
	} from 'vuex'
	export default {
		computed: {
			...mapGetters(['api','userToken']),
		},
		globalData: {
			AppConfig:'',//图片前缀
			openAd:'ca-app-pub-7130333932129753/7006137338',//开屏广告
			bannerAd:'ca-app-pub-7130333932129753/3601831522',//横幅广告（底部）
			bannerCenterAd:'ca-app-pub-7403285017064995/4291647613',//横幅广告（中部）
			insertAd:'ca-app-pub-7130333932129753/2232909536',//插页广告
			insertVideoAd:'ca-app-pub-7130333932129753/4324133670',//插页视频广告
			//测试广告id
			// openAd:'ca-app-pub-3940256099942544/3419835294',//开屏广告
			// bannerAd:'ca-app-pub-3940256099942544/6300978111',//横幅广告（底部）
			// bannerCenterAd:'ca-app-pub-3940256099942544/6300978111',//横幅广告（中部）
			// insertAd:'ca-app-pub-3940256099942544/1033173712',//插页广告
			// insertVideoAd:'ca-app-pub-3940256099942544/8691691433',//插页视频广告（待测试）
		
		},
		data(){
			return{
				isShow:true
			}
		},
		onLaunch: function() {
			console.log('App Launch')
			setInterval(()=>{
				if(this.userToken){
					this.refreshToken()
				}
			},120000)
			//获取App配置
			this.getAppConfig()
			// #ifdef APP-PLUS
			// JYGoogleAdMob.jy_loadInterstitialAd({adId: getApp().globalData.insertAd },res=> {
			// 	console.log('加载插页广告',res);
			// 	if(res.code=='103'||res.code=='101'){
			// 		this.isShow=true
			// 	}
			// 	//展示
			// 	JYGoogleAdMob.jy_showInterstitialAd()
			// })
			JYGoogleAdMob.jy_loadAppOpenAD({ adId: getApp().globalData.openAd }, res=> {
				console.log('加载开屏广告',res);
				if(res.code=='103'||res.code=='101'){
					this.isShow=true
				}
				if(res.code==100){
					JYGoogleAdMob.jy_showAppOpenAD()
				}
			})
			// #endif
			
			
			
		},
		onShow: function() {
			console.log('App Show')
			// #ifdef APP-PLUS
			//获取当前页面窄
			var pages = getCurrentPages();
			var route = (pages[pages.length - 1]).route;
			if(this.isShow==false&&route=="pages/tabBar/index/index"){
				console.log('加载广告');
				JYGoogleAdMob.jy_showAppOpenAD()
			}
			// #endif
		},
		onHide: function() {
			console.log('App Hide')
			this.isShow=false
			// #ifdef APP-PLUS
			JYGoogleAdMob.jy_loadAppOpenAD({adId: getApp().globalData.openAd },res=> {
				if(res.code=='103'||res.code=='101'){
					this.isShow=true
				}
			})
			// #endif
		},
		methods:{
			...mapActions(['set_userToken']),
			//刷新token
			refreshToken(){
				let params={
				}
				uni.$u.http.post(this.api.api_v1_refreshToken, params).then(res => {
					if(res.code==200&&res.data){
						this.set_userToken(res.data.accessToken)
					}
				})
			},
			//获取App配置
			getAppConfig(){
				uni.$u.http.get(this.api.api_v1_getAppConfig, {}).then(res => {
					if(res.code==200&&res.data){
						getApp().globalData.AppConfig=res.data
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "./static/iconfont/iconfont.css";
	/deep/ .mescroll-uni-fixed{
		border-bottom: 1px solid #3c3c3c;
	}
	
	// 状态栏
	.status_bar{height: var(--status-bar-height);width: 100%;}
	
	page{
		height: 100%;background-color: #10182b;
	}
	//日历的颜色
	.uni-calendar__content{
		background-color: #242448!important;color: #fff;
	}
	.uni-calendar--fixed-top{
		border-top-color:#10182b!important;
	}
	.uni-calendar__header-text{
		color: #fff!important;
	}
	.uni-calendar__header{
		border-bottom-color:#10182b!important;color: #fff;
	}
	.uni-calendar__header-btn{
		border-color: #fff!important;
	}
	.uni-calendar__weeks-day{
		border-color: #10182b!important;
	}
	.uni-calendar-item__weeks-box-text,.uni-calendar-item__weeks-lunar-text{
		color: #fff!important;
	}
	.uni-calendar-item--disable{
		background-color: #253966!important;
	}
	
	/* 超出省略 */
	.lz-ellipsis-1 {
		overflow: hidden;white-space: nowrap;text-overflow: ellipsis;
	}
	.lz-ellipsis-2 {
		display: -webkit-box;overflow: hidden; text-overflow: ellipsis;
		/* #ifdef H5 */
		-webkit-box-orient: vertical; -webkit-line-clamp:2;
		/* #endif */
	}
	
	
	/*每个页面公共css */
	@import "@/uni_modules/uview-ui/index.scss";
</style>
